<?php
  if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

  // -- webMS Modification --
  // Check if osCommerce environment is already loaded
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      // Reconnect to osCommerce Database
      tep_db_connect() or die('Unable to connect to database server!');
    }
    // Load osCommerce Globals for Boxes
    global $category_links, $languages_id, $catID, $catID_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    // Load osCommerce Environment for the First Time
    require('components/'.$option.'/includes/application_top.php');
  }
  if (!tep_session_is_registered('login')){
	  require('includes/supplier_area_top.php');
  }
    $suppliers_id = $_SESSION['login'];

  $osCAdminID = $_REQUEST['osCAdminID'];
   require(DIR_WS_LANGUAGES . $language . '/' . $osMod.'.php');
?>

<!-- header //-->
<?php require('includes/header_supplier.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>

    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="contentheading"><?php echo HEADING_TITLE; ?></td>
           
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="sectiontableheader">
                <td class="sectiontableheader"><?php echo TABLE_HEADING_NUMBER; ?></td>
                <td class="sectiontableheader"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
                <td class="sectiontableheader" align="center"><?php echo TABLE_HEADING_VIEWED; ?>&nbsp;</td>
              </tr>
<?php
  if (isset($_REQUEST['page']) && ($_REQUEST['page'] > 1)) $rows = $_REQUEST['page'] * MAX_DISPLAY_SEARCH_RESULTS - MAX_DISPLAY_SEARCH_RESULTS;
  $rows = 0;
  $products_query_raw = "select p.products_id, pd.products_name, pd.products_viewed, l.name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_LANGUAGES . " l where p.products_id = pd.products_id and l.languages_id = pd.language_id and  p.suppliers_id = '" . (int)$suppliers_id . "' order by pd.products_viewed DESC";
  $products_query = tep_db_query($products_query_raw);
  $products_query_numrows = tep_db_num_rows($products_query);
  $products_split = new splitPageResults_SUP($_REQUEST['page'], MAX_DISPLAY_SEARCH_RESULTS, $products_query_raw, $products_query_numrows);
  $products_query = tep_db_query($products_query_raw);
  /*
   $products_query = tep_db_query($products_query_raw);
  $products_query_numrows = tep_db_num_rows($products_query);
  $products_split = new splitPageResults_SUP($_REQUEST['page'], MAX_DISPLAY_SEARCH_RESULTS, $products_query_raw, $products_query_numrows);
  */
  while ($products = tep_db_fetch_array($products_query)) {
    $rows++;

    if (strlen($rows) < 2) {
      $rows = '0' . $rows;
    }
    //tep_href_link(FILENAME_SUPPLIER_S_CATEGORIES_PRODUCTS, 'catID=' . $catID . '&pID=' . $products['products_id'] . '&action=new_product_preview&read=only&origin=' . FILENAME_STATS_PRODUCTS_VIEWED . '?page=' . $_REQUEST['page']')
?>
              <tr class="dataTableRow" onMouseOver="rowOverEffect(this)" onMouseOut="rowOutEffect(this)" >
                <td class="dataTableContent"><?php echo $rows; ?>.</td>
                <td class="dataTableContent"><?php echo '<a href="' . tep_href_link(FILENAME_SUPPLIER_S_CATEGORIES_PRODUCTS, 'catID=' . $catID . '&pID=' . $products['products_id'] . '&action=new_product_preview&read=only&origin=' . FILENAME_SUPPLIER_VIEWED . '?page=' . $_REQUEST['page']) . '">' . $products['products_name'] . '</a> (' . $products['name'] . ')'; ?></td>
                <td class="dataTableContent" align="center"><?php echo $products['products_viewed']; ?>&nbsp;</td>
              </tr>
<?php
  }
?>
            </table></td>
          </tr>
          <tr>
            <td colspan="3"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
                <td class="smallText" valign="top"><?php echo $products_split->display_count($products_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, $_REQUEST['page'], TEXT_DISPLAY_NUMBER_OF_PRODUCTS); ?></td>
                <td class="smallText" align="right"><?php echo $products_split->display_links($products_query_numrows, MAX_DISPLAY_SEARCH_RESULTS, MAX_DISPLAY_PAGE_LINKS, $_REQUEST['page']); ?></td>
              </tr>
            </table></td>
      </tr>
    </table></td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
